package com.test.demos.controller;


import com.test.demos.pojo.entity.UserRole;
import com.test.demos.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.test.demos.utils.Result;
/**
 * (UserRole)表控制层
 *
 * @author twt
 * @since 2025-04-16 17:24:41
 */
@CrossOrigin
@RestController
@RequestMapping("userRole")
public class UserRoleController {
    
    /**
     * 服务对象
     */
    @Autowired
    private UserRoleService userRoleService;
    
    /**
     * 通过ID查询单条数据
     *
     * @param ruId 主键
     * @return 实例对象
     */
    @GetMapping("{id}")
    public Result queryById(@PathVariable("id") Integer ruId){
        return Result.ok(userRoleService.queryById(ruId));
    }
    /**
     * 全部查询
     */
    @GetMapping("all")
    public Result queryAll(){
        return Result.ok(userRoleService.queryAll());
    }

    /**
     * 新增数据
     *
     * @param userRole 实例对象
     * @return 实例对象
     */
    @PostMapping
    public Result add(@RequestBody UserRole userRole){
        userRoleService.add(userRole);
        return Result.ok(userRole);
    }

    /**
     * 更新数据
     *
     * @param userRole 实例对象
     */
    @PutMapping
    public Result update(@RequestBody UserRole userRole){
        userRoleService.update(userRole);
        return Result.ok();
    }

    /**
     * 通过主键删除数据
     *
     * @param ruId 主键
     * @return 是否成功
     */
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id") Integer ruId){
        userRoleService.deleteById(ruId);
        return Result.ok();
    }
}
